﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.PresentationModel;
using SharedGenomics.Domain;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class DataFilterView : View, IDataFilterView
    {
        public DataFilterView()
        {
            InitializeComponent();
            this.Load += (o, e) => { this.Loaded.Raise(this); };
            this.btLoadFileset.Click += (o, e) => { this.LoadFileSetClicked.Raise(this); };
            this.btRefreshFileSets.Click += (o, e) => { this.RefreshFileSetsClicked.Raise(this); };
            this.btSave.Click += (o, e) => { this.CreateDataSetClicked.Raise(this); };
        }

        protected override IEnumerable<Binding> ValidatedDataBindings
        {
            get { return this.bindingSource.CurrencyManager.Bindings.Cast<Binding>(); }
        }

        private void PTO_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            DataFilterPTO pto = (DataFilterPTO)sender;
            this.fileSetsBindingSource.DataSource = pto.AvailableFileSets;
        }

        public event EventHandler Loaded;
        public event EventHandler LoadFileSetClicked;
        public event EventHandler RefreshFileSetsClicked;

        [Region("CategoryFilters")]
        public Panel CategoryFilters
        {
            get { return this.panel1; }
        }

        [Region("FilterResults")]
        public Panel FilterResults
        {
            get { return this.plResults; }
        }

        public bool IsLoadEnabled
        {
            set { this.btLoadFileset.Enabled = value; }
        }

        public bool IsCreateDataSetEnabled
        {
            set { this.btSave.Enabled = value; }
        }

        public string DataSetSaveMessage
        {
            set { this.txtSaveMessage.Text = value; }
        }

        public DataFilterPTO PTO
        {
            set
            {
                this.bindingSource.DataSource = value;
                this.fileSetsBindingSource.DataSource = value.AvailableFileSets;
                value.PropertyChanged += new PropertyChangedEventHandler(this.PTO_PropertyChanged);
            }
        }

        public event EventHandler CreateDataSetClicked;

        public bool IsLoadProgressBarVisible
        {
            set { this.pgbFileSetLoading.Visible = value; }
        }

        public string LoadedFileSetName
        {
            set { this.txtLoadedFileSet.Text = value; }
        }
    }
}
